package com.example.elemboot.Dao;

import com.example.elemboot.Entity.Business;
import com.example.elemboot.Entity.Cart;
import com.example.elemboot.Entity.Food;
import com.example.elemboot.Entity.User;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ICart extends CrudRepository<Cart,Integer> {
    List<Cart> findCartsByBusinessAndUser(Business business, User user);
    Integer countCartsByBusinessAndUser(Business business, User user);
    Cart findCartByBusinessAndFoodAndUser(Business business, Food food, User user);

    @Query("delete from Cart c where c.cartId=:cartId")
    @Modifying  //标识是DML语句
    @Transactional
    void deleteCartByCartId(@Param("cartId") Integer cartId);

}
